package com.itheima.boottlias.exhandler;

import com.itheima.boottlias.domain.vo.Result;
import com.itheima.boottlias.ex.CustomException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 * @author ghy
 * @version 1.0
 * @since 2025-07-14 15:02
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler
    public Result handleException(Exception e){
        log.error("{}", e);
        return Result.error("服务器正忙，请稍后重试！！");
    }

    /**
     * 处理自定义异常
     * @param e
     * @return
     */
    @ExceptionHandler
    public Result handleCustomException(CustomException e){
        log.error("{}", e);
        return Result.error(e.getMessage());
    }

}